
import 'package:flutter/cupertino.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/base/BaseController.dart';
import 'package:xin_nuo_pda/bean/lot_entity.dart';
import 'package:xin_nuo_pda/bean/product_lib_entity.dart';

import '../../http/api/lot_api.dart';
import '../../routes/Routes.dart';

class ProductIntoLibController extends BaseController{
  List<LotEntity> lotList = [];

  String LOTID = 'LOTID';

  List<String> lotData = [];

  TextEditingController textEditingController = TextEditingController();


  lotInfo(String lot) async{
    Map<String, dynamic> params = {'LOTID':lot};
    var result = await LotApi.lotInfo(canelToken,params: params);
    if(result.ok){
      LotEntity lotEntity = result.data ?? LotEntity();
      if(lotData.contains(lotEntity.lOTID)){
        Get.snackbar('提示', '当前批次已添加');
      }else{
        lotData.add(lotEntity.lOTID ?? '');
        lotList.add(lotEntity);
        update([LOTID]);
      }

      textEditingController.text = '';
    }
  }

  lotShip() async{
    if(lotList.isEmpty){
      Get.snackbar('提示', '请先添加批次列表');
      return;
    }

    List<ProductLibEntity> data = [];
    lotList.forEach((element) {
      ProductLibEntity entity = ProductLibEntity();
      entity.LOTID = element.lOTID;
      entity.ATTRIBUTE4 = element.CARRIER_ID;
      entity.LOTCOMMENT = element.CYCLE;
      data.add(entity);
    });

    Map<String, dynamic> params = {'ACTIONTYPE':'P','LOTLIST' : data};
    var result = await LotApi.getLotShip(canelToken,params: params);
    if(result.ok){
      Fluttertoast.showToast(
        msg: "入库成功",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
      );

      Get.offAllNamed(Routes.Tabs);
    }


  }

}